package ar.edu.itba.it.cg.grupo01.impl.texture;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.vecmath.Point2f;

import ar.edu.itba.it.cg.grupo01.api.texture.Texture;
import ar.edu.itba.it.cg.grupo01.api.texture.TextureFilter;

public class TextureImpl implements Texture {

	private BufferedImage tex;
	private TextureFilter filter;

	public TextureImpl(File textureFile, TextureFilter filter)
			throws IOException {
		this.tex = ImageIO.read(textureFile);
		this.filter = filter;
	}

	public TextureImpl(BufferedImage texture) {
		this.tex = texture;
		this.filter = new defaultTextureFilter();
	}

	public TextureImpl(BufferedImage texture, TextureFilter filter) {
		this.tex = texture;
		this.filter = filter;
	}

	public Color getColorAtPoint(Point2f uvPoint) {
		float u = uvPoint.x;
		float v = uvPoint.y;
		return filter.getTextureColor(u, v, tex);
	}

}
